package com.yueyang.sojourn.server.validation.annotation;

/**
 * @author yemingxing
 * @summary 枚举值 参数校验
 * @Copyright (c) 2020, Yueyang Group All Rights Reserved.
 * @since 2020-02-15 15:24
 */

import com.yueyang.sojourn.server.model.enums.IEnum;
import com.yueyang.sojourn.server.validation.EnumValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Documented
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Repeatable(EnumValid.List.class)
@Constraint(validatedBy = {EnumValidator.class})
public @interface EnumValid {

    String message() default "枚举值错误";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * the enum's class-type
     *
     * @return Class
     */
    Class<? extends IEnum> clazz();

    /**
     * Defines several {@link EnumValid} annotations on the same element.
     *
     * @see EnumValid
     */
    @Documented
    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @interface List {
        EnumValid[] value();
    }
}

